<template>
	<view>
		<uni-nav-bar statusBar left-icon="left" @clickLeft="navBack" fixed backgroundColor='#3f6efe' color='#fff'>
			<view class="w-100p flex-c flex-aic f-28">用户管理</view>
		</uni-nav-bar>
		<uniSwipeAcion>
			<view v-for="(item,index) in list" :key="index" class="m-l-25 m-r-25 m-t-30"> 
				<uniSwipeAcionItem :right-options="options1" :left-options="options2" @click="onClick($event,index,item)" >
					<view :class="item.is_delete==0?'bgc-white':'bgc-disabled'"
						class=" br-12  p-25  flex flex-aic" >
				
						<image mode="widthFix" class="w-100 h-100 br-50p bgc-ee m-r-20" :src="item.avatar"></image>
						<view class="flex-1 f-22">
							<view class="flex flex-sb">
								<text>姓名:{{item.username}}</text>
								<text>注册时间:{{item.create_time}}</text>
							</view>
							<view>手机号:{{item.phone?item.phone:'暂无'}}</view>
						</view>
					</view>
				</uniSwipeAcionItem>
			</view>
			
		</uniSwipeAcion>

		<!-- 缺省 -->
		<pinapp-empty-page v-if="list.length==0"></pinapp-empty-page>

		<!-- 加载状态 -->
		<block v-if="list.length!=0">
			<view class="p-b-100">
				<uni-load-more :status="status"></uni-load-more>
			</view>
		</block>


	</view>
</template>

<script>
	import pinappEmptyPage from "@/components/pinapp-empty-page/pinapp-empty-page.vue"
	import uniSwipeAcion from '@/uni_modules/uni-swipe-action/components/uni-swipe-action/uni-swipe-action'
	import uniSwipeAcionItem from '@/uni_modules/uni-swipe-action/components/uni-swipe-action-item/uni-swipe-action-item'
	export default {
		components: {
			pinappEmptyPage,
			uniSwipeAcion,
			uniSwipeAcionItem
		},
		data() {
			return {
				params: {
					page: 1,
					limit: 10
				},
				options1: [{
					text: '禁用',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				options2: [{
					text: '启用',
					style: {
						backgroundColor: '#007aff'
					}
				}],
				list: [],
				status: 'more'

			}
		},
		onLoad() {
			this.getlist()
		},
		methods: {
			getlist() {
				this.$http.get('/admin/userlist', {
					params: this.params
				}).then(res => {
					this.list = this.list.concat(res.data.list)
					this.params.page++
					if (this.list.length >= res.data.total) {
						this.status = 'no-more'
					} else {
						this.status = 'more'
					}

				})
			},
			onClick(e,index,item) {
				let type = ''
				if (e.position === 'left') {//启用
					type =0
				} else {//禁用
					type =1
				}
				this.$http.post('/admin/user_isdelete',Object.assign({id:item.id},{type})).then(res=>{
					type===1?item.is_delete=1:item.is_delete=0
				})
			}

		},
		onReachBottom() {
			this.getlist()
		}
	}
</script>

<style>
</style>
